#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import logging

print('数组'.center(30, '#'))
classmates = ['apple', 'banana', 'cursor', 'depth', "apple", 'apple', 'apple']
print(len(classmates), classmates[0], classmates[1], classmates[2], classmates[3])
print(len(classmates), classmates[-4], classmates[-3], classmates[-2], classmates[-1])

print('数组中追加元素到末尾'.center(30, '#'))
classmates.append("元素到末尾")
print(len(classmates), classmates)

print('数组中追加元素到指定位置之前'.center(30, '#'))
classmates.insert(0, "元素到指定位置0之前")
print(len(classmates), classmates)

print('数组中pop()删除元素'.center(30, '#'))
classmates.pop(2)
print(len(classmates), classmates)

print('数组中元素的类型可以不同，也可以是数组'.center(30, '#'))
classmates = [[1, 2, 3, 4], 'banana', ['apple', 'banana', 'cursor', 'depth'], 'depth', "apple", 'apple', 'apple']
print(len(classmates), classmates)

print('数组中remove()删除元素，没有这个元素，会报错'.center(30, '#'))
try:
    classmates.remove('元素到指定位置0之前')
except Exception as e:
    logging.exception(e)

print(len(classmates), classmates)

print('数组中count()统计元素'.center(30, '#'))
print(classmates.count('apple'), classmates.count(""))

print('数组中index()返回元素索引'.center(30, '#'))
print(classmates.index('apple'))

print('数组中reverse()反转数组'.center(30, '#'))
classmates.reverse()
print(classmates)

print('数组中sort()数组排序（列表中的元素类型必须相同）'.center(30, '#'))
classmates.pop(6)
classmates.pop(4)
classmates.sort()
print(classmates)
classmates.sort(reverse=True)
print(classmates)

print('数组扩展'.center(30, '#'))
other_classmates = ["water", "cup", 'orange']
print(classmates + other_classmates)

print(classmates.extend(other_classmates))
